package com.evan.kdl.test.day02;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * join() 更适合用在流式编程中。
 */
public class GetOrJoinDemo {
    public static void main(String[] args) {
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            return "hello";
        });

        String ret = null;
        // 抛出检查时异常，必须处理
        try {
            ret = future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("ret = " + ret);

        // 抛出运行时异常，可以不处理
        ret = future.join();
        System.out.println("ret = " + ret);
    }
}